﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 项目4
{
    public partial class _4_5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {     //判断是否处于编辑模式
            if ((e.Row.RowState & DataControlRowState.Edit) <= 0)
            {    //若为正常显示模式，判断当前行类型是否为数据
                if (e.Row.RowType == DataControlRowType.DataRow)
                {  //从当前行的第3个单元格中读取新闻发布时间，索引从0开始
                    string createTime = e.Row.Cells[2].Text;
                    //计算距离发布时间的间隔
                    TimeSpan ts = DateTime.Now.Subtract(DateTime.Parse(createTime));
                    //在当期行中查找在模板中放置的标签控件       减
                    Label lblDays = (Label)e.Row.FindControl("Label1");
                    //显示时间间隔对应的天数
                    lblDays.Text = ts.Days.ToString("#,##0");
                }
            }
        }


    }
}